/*     */ package nccloud.framework.web.convert.pattern;
/*     */ 
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import nc.vo.pub.AggregatedValueObject;
/*     */ import nc.vo.pub.CircularlyAccessibleValueObject;
/*     */ import nc.vo.pub.SuperVO;
/*     */ import nc.vo.pubapp.pattern.pub.Constructor;
/*     */ import nccloud.framework.core.exception.ExceptionUtils;
/*     */ import nccloud.framework.core.model.entity.IBill;
/*     */ import nccloud.framework.core.model.entity.IVO;
/*     */ import nccloud.framework.core.model.meta.IVOMeta;
/*     */ import nccloud.framework.core.util.ArrayUtils;
/*     */ import nccloud.framework.web.ui.pattern.billcard.BillCard;
/*     */ import nccloud.framework.web.ui.pattern.billcard.SpecilAggBill;
/*     */ import nccloud.framework.web.ui.pattern.form.Form;
/*     */ import nccloud.framework.web.ui.pattern.grid.Grid;
/*     */ import nccloud.pubitf.platform.pub.IOperateGrandSon;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BillCardConvertor
/*     */ {
/*     */   private String[] bodyattrs;
/*     */   private String[] headattrs;
/*     */   
/*     */   public <T> T fromBillCard(Class<T> billclazz, BillCard card, CardAreaInfo[] infos) {
/*  54 */     T bill = (T)Constructor.construct(billclazz);
/*  55 */     if (bill instanceof AggregatedValueObject) {
/*  56 */       fillBill((AggregatedValueObject)bill, card, infos);
/*  57 */     } else if (bill instanceof SpecilAggBill) {
/*  58 */       fillBill((SpecilAggBill)bill, card, infos);
/*     */     } else {
/*  60 */       ExceptionUtils.unSupported();
/*     */     } 
/*  62 */     return bill;
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*  71 */   public void setBodyattrs(String[] bodyattrs) { this.bodyattrs = bodyattrs; }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*  80 */   public void setHeadattrs(String[] headattrs) { this.headattrs = headattrs; }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public BillCard toBillCard(Object vo, CardAreaInfo[] infos) {
/*  93 */     BillCard card = null;
/*  94 */     if (vo instanceof AggregatedValueObject) {
/*  95 */       AggregatedValueObject bill = (AggregatedValueObject)vo;
/*  96 */       card = toBillCard(bill, infos);
/*  97 */     } else if (vo instanceof IBill) {
/*  98 */       IBill bill = (IBill)vo;
/*  99 */       card = toBillCard(bill, infos);
/* 100 */     } else if (vo instanceof SpecilAggBill) {
/* 101 */       SpecilAggBill bill = (SpecilAggBill)vo;
/* 102 */       card = toBillCard(bill, infos);
/*     */     } else {
/* 104 */       ExceptionUtils.unSupported();
/*     */     } 
/* 106 */     return card;
/*     */   }
/*     */   
/*     */   private void createBody(CardAreaInfo info, BillCard card, Object[] vos) {
/* 110 */     GridConvertor convertor = new GridConvertor();
/* 111 */     Grid body = null;
/* 112 */     String[] names = null;
/*     */     
/* 114 */     if (this.bodyattrs != null && this.bodyattrs.length > 0) {
/* 115 */       names = this.bodyattrs;
/*     */     } else {
/* 117 */       names = info.getNames();
/*     */     } 
/*     */     
/* 120 */     if (names.length == 0) {
/* 121 */       body = convertor.toGrid(info.getAreacode(), vos);
/*     */     } else {
/* 123 */       body = convertor.toGrid(info.getAreacode(), vos, names);
/*     */     } 
/* 125 */     card.setBody(body);
/*     */   }
/*     */   
/*     */   private void createHeadTail(CardAreaInfo[] infos, BillCard card, Object vo) {
/* 129 */     Form head = null;
/* 130 */     for (CardAreaInfo info : infos) {
/* 131 */       FormConvertor convertor = new FormConvertor();
/* 132 */       String[] names = null;
/*     */       
/* 134 */       if (this.headattrs != null && this.headattrs.length > 0) {
/* 135 */         names = this.headattrs;
/*     */       } else {
/* 137 */         names = info.getNames();
/*     */       } 
/*     */       
/* 140 */       if (names.length == 0) {
/* 141 */         head = convertor.toForm(info.getAreacode(), vo);
/*     */       } else {
/* 143 */         head = convertor.toForm(info.getAreacode(), vo, names);
/*     */       } 
/* 145 */       if (info.getPosition() == CardPosition.Tail) {
/* 146 */         card.setTail(head);
/*     */       } else {
/* 148 */         card.setHead(head);
/*     */       } 
/*     */     } 
/*     */   }
/*     */   
/*     */   private void fillBill(AggregatedValueObject bill, BillCard card, CardAreaInfo[] infos) {
/* 154 */     Map<String, IOperateGrandSon> bodyVOMap = new HashMap<String, IOperateGrandSon>();
/* 155 */     String bodyPkField = null;
/* 156 */     for (CardAreaInfo info : infos) {
/* 157 */       if (info.getPosition() == CardPosition.Head) {
/* 158 */         FormConvertor convertor = new FormConvertor();
/* 159 */         Form form = card.getHead();
/* 160 */         if (form != null)
/*     */         
/*     */         { 
/* 163 */           SuperVO head = (SuperVO)convertor.fromForm(info.getClazz(), form);
/* 164 */           bill.setParentVO(head); } 
/* 165 */       } else if (info.getPosition() == CardPosition.Body && !info.isGrandSon()) {
/* 166 */         GridConvertor convertor = new GridConvertor();
/* 167 */         Grid grid = card.getBody();
/* 168 */         SuperVO[] vos = (SuperVO[])convertor.fromGrid(info.getClazz(), grid);
/* 169 */         bill.setChildrenVO(vos);
/* 170 */         if (null != vos && vos.length > 0 && 
/* 171 */           IOperateGrandSon.class.isAssignableFrom(info.getClazz())) {
/* 172 */           for (SuperVO vo : vos) {
/* 173 */             bodyVOMap.put((vo.getPrimaryKey() == null) ? (String)vo.getAttributeValue("rowid") : vo.getPrimaryKey(), (IOperateGrandSon)vo);
/* 174 */             bodyPkField = ((IOperateGrandSon)vo).getBodyPkField(null);
/*     */           } 
/*     */         }
/*     */       } 
/*     */     } 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */     
/* 186 */     Set<String> keySet = bodyVOMap.keySet();
/* 187 */     if (keySet.size() > 0) {
/* 188 */       for (CardAreaInfo info : infos) {
/* 189 */         if (info.isGrandSon()) {
/* 190 */           GridConvertor convertor = new GridConvertor();
/* 191 */           Grid girdData = card.getGrandSon(info.getAreacode());
/*     */           
/* 193 */           if (null != girdData) {
/* 194 */             SuperVO[] grandSonVos = (SuperVO[])convertor.fromGrid(info.getClazz(), girdData);
/* 195 */             Map<String, List<SuperVO>> bodyPkGrandSonMap = new HashMap<String, List<SuperVO>>();
/* 196 */             for (SuperVO vo : grandSonVos) {
/* 197 */               String pkBody = (String)vo.getAttributeValue(bodyPkField);
/* 198 */               if (bodyPkGrandSonMap.get(pkBody) == null) {
/* 199 */                 List<SuperVO> grandSons = new ArrayList<SuperVO>();
/* 200 */                 grandSons.add(vo);
/* 201 */                 bodyPkGrandSonMap.put(pkBody, grandSons);
/*     */               } else {
/* 203 */                 ((List)bodyPkGrandSonMap.get(pkBody)).add(vo);
/*     */               } 
/*     */               
/* 206 */               SuperVO myBodyVo = (SuperVO)bodyVOMap.get(pkBody);
/* 207 */               if (myBodyVo.getPrimaryKey() == null || "".equals(myBodyVo.getPrimaryKey().trim())) {
/* 208 */                 vo.setAttributeValue(((IOperateGrandSon)bodyVOMap.get(pkBody)).getBodyPkField(info.getClazz().getName()), null);
/*     */               }
/*     */             } 
/* 211 */             for (String bodyKey : keySet) {
/* 212 */               IOperateGrandSon body = (IOperateGrandSon)bodyVOMap.get(bodyKey);
/* 213 */               List<SuperVO> grandSons = (List)bodyPkGrandSonMap.get(bodyKey);
/* 214 */               if (grandSons != null && grandSons.size() > 0) {
/* 215 */                 body.setGrandSon(info.getClazz().getName(), grandSons);
/*     */               }
/*     */             } 
/*     */           } 
/*     */         } 
/*     */       } 
/*     */     }
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   private void fillBill(SpecilAggBill bill, BillCard card, CardAreaInfo[] infos) {
/* 227 */     for (CardAreaInfo info : infos) {
/* 228 */       if (info.getPosition() == CardPosition.Head) {
/* 229 */         FormConvertor convertor = new FormConvertor();
/* 230 */         Form form = card.getHead();
/* 231 */         if (form != null)
/*     */         
/*     */         { 
/* 234 */           SuperVO head = (SuperVO)convertor.fromForm(info.getClazz(), form);
/* 235 */           bill.setHead(head); } 
/* 236 */       } else if (info.getPosition() == CardPosition.Body) {
/* 237 */         if (!info.isGrandSon()) {
/* 238 */           GridConvertor convertor = new GridConvertor();
/* 239 */           Grid grid = card.getBody();
/* 240 */           SuperVO[] vos = (SuperVO[])convertor.fromGrid(info.getClazz(), grid);
/* 241 */           bill.setBodys(vos);
/*     */         } else {
/* 243 */           String className = info.getClazz().getSimpleName();
/* 244 */           GridConvertor convertor = new GridConvertor();
/* 245 */           Grid grid = card.getGrandSon(className);
/* 246 */           SuperVO[] vos = (SuperVO[])convertor.fromGrid(info.getClazz(), grid);
/* 247 */           bill.setGrandSons(className, vos);
/*     */         } 
/*     */       } 
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   private CardAreaInfo[] find(CardAreaInfo[] infos, Class<?> clazz) {
/* 258 */     List<CardAreaInfo> list = new ArrayList<CardAreaInfo>();
/* 259 */     for (CardAreaInfo info : infos) {
/* 260 */       if (clazz.equals(info.getClazz())) {
/* 261 */         list.add(info);
/*     */       }
/*     */     } 
/* 264 */     int size = list.size();
/* 265 */     CardAreaInfo[] ret = new CardAreaInfo[size];
/* 266 */     return (CardAreaInfo[])list.toArray(ret);
/*     */   }
/*     */ 
/*     */   
/*     */   private CardAreaInfo[] find(CardAreaInfo[] infos, String vometa) {
/* 271 */     List<CardAreaInfo> list = new ArrayList<CardAreaInfo>();
/* 272 */     for (CardAreaInfo info : infos) {
/* 273 */       if (vometa.equals(info.getVometa())) {
/* 274 */         list.add(info);
/*     */       }
/*     */     } 
/* 277 */     int size = list.size();
/* 278 */     CardAreaInfo[] ret = new CardAreaInfo[size];
/* 279 */     return (CardAreaInfo[])list.toArray(ret);
/*     */   }
/*     */ 
/*     */   
/*     */   private BillCard toBillCard(AggregatedValueObject bill, CardAreaInfo[] infos) {
/* 284 */     BillCard card = new BillCard();
/* 285 */     Object vo = bill.getParentVO();
/* 286 */     if (vo != null) {
/* 287 */       CardAreaInfo[] rets = find(infos, vo.getClass());
/* 288 */       createHeadTail(rets, card, vo);
/*     */     } 
/* 290 */     CircularlyAccessibleValueObject[] arrayOfCircularlyAccessibleValueObject = bill.getChildrenVO();
/* 291 */     if (arrayOfCircularlyAccessibleValueObject != null && arrayOfCircularlyAccessibleValueObject.length > 0) {
/* 292 */       CardAreaInfo[] rets = find(infos, arrayOfCircularlyAccessibleValueObject[0].getClass());
/* 293 */       if (rets == null || rets.length == 0) {
/* 294 */         return card;
/*     */       }
/* 296 */       createBody(rets[0], card, arrayOfCircularlyAccessibleValueObject);
/*     */       
/* 298 */       if (arrayOfCircularlyAccessibleValueObject[0] instanceof IOperateGrandSon) {
/* 299 */         String[] grandSonClasses = ((IOperateGrandSon)arrayOfCircularlyAccessibleValueObject[0]).getGrandSonClass();
/* 300 */         for (String grandSonClass : grandSonClasses) {
/* 301 */           Object[] grandSonVos = null;
/* 302 */           for (Object bodyVO : arrayOfCircularlyAccessibleValueObject) {
/* 303 */             IOperateGrandSon body = (IOperateGrandSon)bodyVO;
/* 304 */             SuperVO[] grandSons = body.getGrandSon(grandSonClass);
/* 305 */             if (grandSons != null && grandSons.length > 0) {
/* 306 */               Object[] objs = ArrayUtils.mergeArrays(grandSonVos, grandSons);
/* 307 */               grandSonVos = objs;
/*     */             } 
/*     */           } 
/* 310 */           if (grandSonVos != null && grandSonVos.length > 0) {
/* 311 */             CardAreaInfo[] grandArea = find(infos, grandSonVos[0].getClass());
/* 312 */             createGrandSon(grandArea[0], card, grandSonVos);
/*     */           } 
/*     */         } 
/*     */       } 
/*     */     } 
/*     */ 
/*     */ 
/*     */ 
/*     */     
/* 321 */     return card;
/*     */   }
/*     */   
/*     */   private BillCard toBillCard(IBill bill, CardAreaInfo[] infos) {
/* 325 */     BillCard card = new BillCard();
/* 326 */     IVO vo = bill.getParent();
/* 327 */     if (vo != null) {
/* 328 */       String vometa = vo.getMeta().getEntityFullName();
/* 329 */       CardAreaInfo[] rets = find(infos, vometa);
/* 330 */       createHeadTail(rets, card, vo);
/*     */     } 
/*     */     
/* 333 */     IVOMeta[] metas = bill.getMetaData().getChildren();
/* 334 */     if (metas == null) {
/* 335 */       return card;
/*     */     }
/* 337 */     IVO[] vos = bill.getChildren(metas[0]);
/* 338 */     if (vos != null && vos.length > 0) {
/* 339 */       String vometa = vos[0].getMeta().getEntityFullName();
/* 340 */       CardAreaInfo[] rets = find(infos, vometa);
/* 341 */       createBody(rets[0], card, vos);
/*     */     } 
/* 343 */     return card;
/*     */   }
/*     */   
/*     */   private BillCard toBillCard(SpecilAggBill bill, CardAreaInfo[] infos) {
/* 347 */     BillCard card = new BillCard();
/* 348 */     SuperVO head = bill.getHead();
/* 349 */     if (head != null) {
/* 350 */       CardAreaInfo[] rets = find(infos, head.getClass());
/* 351 */       createHeadTail(rets, card, head);
/*     */     } 
/*     */     
/* 354 */     SuperVO[] bodys = bill.getBodys();
/* 355 */     if (bodys != null && bodys.length > 0) {
/* 356 */       CardAreaInfo[] rets = find(infos, bodys[0].getClass());
/* 357 */       if (rets == null || rets.length == 0) {
/* 358 */         return card;
/*     */       }
/* 360 */       createBody(rets[0], card, bodys);
/*     */     } 
/*     */     
/* 363 */     if (bill.grandSons != null && bill.grandSons.size() > 0) {
/* 364 */       Set<String> classNames = bill.grandSons.keySet();
/* 365 */       for (String className : classNames) {
/* 366 */         SuperVO[] grandSonArray = (SuperVO[])bill.grandSons.get(className);
/* 367 */         if (grandSonArray != null && grandSonArray.length > 0) {
/* 368 */           CardAreaInfo[] rets = find(infos, grandSonArray[0].getClass());
/* 369 */           if (rets == null || rets.length == 0) {
/* 370 */             return card;
/*     */           }
/* 372 */           createGrandSon(rets[0], card, grandSonArray);
/*     */         } 
/*     */       } 
/*     */     } 
/*     */     
/* 377 */     return card;
/*     */   }
/*     */ 
/*     */   
/*     */   private void createGrandSon(CardAreaInfo info, BillCard card, Object[] vos) {
/* 382 */     GridConvertor convertor = new GridConvertor();
/* 383 */     Grid grandSon = null;
/* 384 */     String[] names = null;
/*     */     
/* 386 */     if (this.bodyattrs != null && this.bodyattrs.length > 0) {
/* 387 */       names = this.bodyattrs;
/*     */     } else {
/* 389 */       names = info.getNames();
/*     */     } 
/*     */     
/* 392 */     if (names.length == 0) {
/* 393 */       grandSon = convertor.toGrid(info.getAreacode(), vos);
/*     */     } else {
/* 395 */       grandSon = convertor.toGrid(info.getAreacode(), vos, names);
/*     */     } 
/* 397 */     card.setGrandSon(info.getAreacode(), grandSon);
/*     */   }
/*     */ }


/* Location:              E:\zhuhai_ncc\NCC2111\external\lib\pubplatform_baseLevel-1.jar!/nccloud/framework/web/convert/pattern/BillCardConvertor.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */